<template>
  <el-row>
    <edit-modal ref="editModal" @refresh="refresh"></edit-modal>
    <el-col :span="24">
      <el-card class="search-form">
        <el-form ref="searchForm" class="el-form-col el-form-s" :model="search" label-position="left" label-width="15px">
          <el-row :gutter="15">
            <el-col :span="6">
              <el-form-item  prop="companyName">
                <el-input v-model="search.companyName" placeholder="公司全称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item prop="logAccount">
                <el-input v-model="search.contactName" placeholder="联系人姓名" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item prop="logAccount">
                <el-input v-model="search.contactPhone" placeholder="联系人电话" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item  prop="auditType">
                <el-select v-model="search.auditType" placeholder="请选择审核类型">
                  <el-option v-for="item in pickingTypeArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item  prop="auditState">
                <el-select v-model="search.auditState" placeholder="请选择审核状态">
                  <el-option v-for="item in auditStateArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="2" class="text-center">
              <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
            </el-col>
            <el-col :span="2" class="text-center">
              <el-button @click="resetFields" plain>重置</el-button>
            </el-col>
          </el-row>

          <el-collapse-transition>
            <template  v-if="isOpen">
            </template>
          </el-collapse-transition>
        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/trunk-audit/getTrunkAuditList"
        :tabs="tabs"
        :columns="columns">
        <!--<template slot="buttons">-->
          <!--<el-button type="primary" @click="add">新增</el-button>-->
        <!--</template>-->
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="detailId(scope.row.id)"
              >
                详情
              </el-button>
              <el-button
                v-if = 'scope.row.auditState == 0'
                size="mini"
                type="text"
                @click="aduit(scope.row.id)"
              >
                通过
              </el-button>
              <el-button
                v-if = 'scope.row.auditState == 0'
                size="mini"
                type="text"
                @click="aduitNo(scope.row.id)"
              >
                不通过
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>
<script>
import EditModal from '@/views/oms/resource/pick/EditModal'
import {unixTimestampFilter, auditStatusFilter} from '@/filters'
import {copy} from '@/utils'
import {getSubDictListOfParentCode} from '@/utils/selectOptions'
export default {
  name: 'resourcePick',
  components: {
    EditModal
  },
  data() {
    let columns = [
      {
        label: '公司全称',
        data: 'companyName'
      },
      {
        label: '联系人姓名',
        data: 'contactsName'
      },
      {
        label: '联系人电话',
        data: 'contactsPhone'
      },
      {
        label: '申请人账号',
        data: 'applyPhone'
      },
      {
        label: '审核类型',
        data: 'auditTypeName'
        // render(data, full) {
        //   return filterDataBaseDictionary(data)
        // }
      },
      {
        label: '审核状态',
        data: 'auditState',
        render(data, full) {
          return auditStatusFilter(data)
        }
      },
      {
        label: '申请时间',
        data: 'applyTime',
        render(data, full) {
          return unixTimestampFilter(data)
        }
      }
    ]
    return {
      pickingTypeArr: [],
      isOpen: false,
      visible: false,
      searchLoading: false,
      search: {
        companyName: '',
        contactName: '',
        contactPhone: '',
        auditType: '',
        auditState: ''
      },
      auditStateArr: [
        {value: '0', text: '待审核'},
        {value: '1', text: '通过'},
        {value: '2', text: '驳回'}],
      columns,
      tabs: []
    }
  },
  created() {
    getSubDictListOfParentCode('AUDITTYPE').then(arr => {
      this.pickingTypeArr = arr
    })
  },
  methods: {
    // 搜索
    searchFunc(search) {
      console.log(search, 'testtest')
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    // 重置表单
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
      this.search = {}
    },
    valueChanged(data) {
      this.$refs.editModal.show(data)
    },
    // 表格刷新
    refresh() {
      this.searchFunc(this.search)
    },
    detailId(id) {
      this.$router.push({path: '/ss-oms/approve/detail/' + id})
    },
    editRowId(data) {
      this.$refs.editModal.show(data)
    },
    delRowId(data) {
    },
    aduitNo(id) {
      this.$prompt('不通过理由', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[\s\S]{0,20}$/,
        inputPlaceholder: '不超过20个字!',
        inputErrorMessage: '字数超过限制'
      }).then(({ value }) => {
        // 这里调不通过的接口
        this.$ajax.post('/ms-warehouse-order/trunk-audit/auditTrunkCertificated', {id: id, auditState: 2, auditMemo: value}).then(response => {
          if (response.success) {
            this.refresh()
            this.$message({
              type: 'success',
              message: '已拒绝通过'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    aduit(id) {
      // 通过 这里调通过的接口
      this.$ajax.post('/ms-warehouse-order/trunk-audit/auditTrunkCertificated', {id: id, auditState: 1}).then(response => {
        if (response.success) {
          this.refresh()
          this.$message({
            type: 'success',
            message: '已审核通过'
          })
        }
      })
    }
  }
}
</script>
